<?php

namespace App\Http\Controllers;

use App\Library\Requests\Base\IdRequest;
use App\Library\Requests\Im\ImAddRequest;
use App\Library\Requests\Im\ImNewRequest;
use App\Library\Requests\Im\ImPageRequest;
use App\Library\Service\ImService;
use Illuminate\Http\JsonResponse;

class ImController extends BaseController
{
    /**
     * @param ImService $service
     */
    public function __construct(ImService $service)
    {
        $this->service = $service;
    }

    /**
     * 分页
     * @param ImPageRequest $request
     * @return JsonResponse
     */
    public function paging(ImPageRequest $request): JsonResponse
    {
        if (USERID === 0) return failMessage('用户失效或不存在');
        else return $this->service->paging($request);
    }

    /**
     * 最新
     * @param ImNewRequest $request
     * @return JsonResponse
     */
    public function new(ImNewRequest $request): JsonResponse
    {
        if (USERID === 0) return failMessage('用户失效或不存在');
        else return $this->service->new($request);
    }

    /**
     * add
     * @param ImAddRequest $request
     * @return JsonResponse
     */
    public function add(ImAddRequest $request): JsonResponse
    {
        if (USERID === 0) return failMessage('用户失效或不存在');
        else return $this->service->add($request);
    }

    /**
     * userInfo
     * @param IdRequest $request
     * @return JsonResponse
     */
    public function userInfo(IdRequest $request): JsonResponse
    {
        if (USERID === 0) return failMessage('用户失效或不存在');
        else return $this->service->userInfo($request);
    }
}
